using System;
using System.Data;
using System.Windows.Forms;

namespace HopFieldTest
{
    public partial class Display : UserControl
    {
        public Display()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Sets the output to the simulated display
        /// </summary>
        /// <param name="pdrResult">The Example DataRow to load</param>
        public void SetDisplay(DataRow pdrResult)
        {
            CheckBox chkToSet;
            //cleans the display
            for (int i = 0; i < 60; i++)
            {   
                chkToSet = (CheckBox)(Controls.Find("checkBox" + (i + 1), true)[0]);
                chkToSet.Checked = false;                
            }   

            //sets the values
            for (int i = 0; i < 60; i++)
			{   
                chkToSet = (CheckBox)(Controls.Find("checkBox" + (i + 1), true)[0]);
                chkToSet.Checked = (Convert.ToInt32(pdrResult[i]) == 1) ? true : false;                
			}            
        }

        /// <summary>
        /// Sets the output to the simulated display
        /// </summary>
        /// <param name="pintResult">The int array to load</param>
        public void SetDisplay(int[] pintResult)
        {
            CheckBox chkToSet;
            //clears the display
            for (int i = 0; i < 60; i++)
            {
                chkToSet = (CheckBox)(Controls.Find("checkBox" + (i + 1), true)[0]);
                chkToSet.Checked = false;
            }

            //sets the display
            for (int i = 0; i < 60; i++)
            {
                chkToSet = (CheckBox)(Controls.Find("checkBox" + (i + 1), true)[0]);
                chkToSet.Checked = (pintResult[i] == 1) ? true : false;
            }
        }

        /// <summary>
        /// Translates the Display Value to an int array
        /// </summary>
        /// <returns></returns>
        public int[] GetDisplay()
        {
            int[] intResult = new int[60];
            CheckBox chkToSet;
            for (int i = 0; i < 60; i++)
            {   
                chkToSet = (CheckBox)(Controls.Find("checkBox" + (i + 1), true)[0]);
                intResult[i] = (chkToSet.Checked) ? 1 : -1;                
            } 
            return intResult;
        }

        /// <summary>
        /// Gives better constrast to the control
        /// </summary>
        public void DarkenMe()
        {
            CheckBox chkToSet;
            //cleans the display
            for (int i = 0; i < 60; i++)
            {
                chkToSet = (CheckBox)(Controls.Find("checkBox" + (i + 1), true)[0]);
                chkToSet.Visible = chkToSet.Checked;
            }
        }

        /// <summary>
        /// Return the control to the normal style
        /// </summary>
        public void ToNomal()
        {
            CheckBox chkToSet;
            //cleans the display
            for (int i = 0; i < 60; i++)
            {
                chkToSet = (CheckBox)(Controls.Find("checkBox" + (i + 1), true)[0]);
                chkToSet.Visible = true;
            }
        }
    }
}
